﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using KendoMvcUI.Common;

namespace KendoMvcUI.Core
{
    public class MVCUIBase
    {
        /// <summary>
        /// ViewContext
        /// </summary>
        protected virtual ViewContext ViewContext { get; private set; }
        /// <summary>
        /// ViewDataContainer
        /// </summary>
        protected virtual IViewDataContainer ViewDataContainer { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public ControlSettingsBase Settings{get;set;}
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="context"></param>
        /// <param name="viewDataContainer"></param>
        protected MVCUIBase(ControlSettingsBase settings, 
            ViewContext context, IViewDataContainer viewDataContainer)
            :this(settings)
        {
            ViewContext = context;
            ViewDataContainer = viewDataContainer;
        }
        public MVCUIBase(ControlSettingsBase settings)
        {
            this.Settings = settings;
        }
        /// <summary>
        /// 根据kendo Js 生成字符串
        /// </summary>
        /// <returns></returns>
        public virtual string RenderJavascript()
        {
            string script = Settings.ToJsSettings();
            if(!script.IsNullOrWhiteSpace())
                script = "{" + script+"}";
            
            return script;
        }
        public override string ToString()
        {
            return RenderJavascript();
        }
        /// <summary>
        /// 返回Html string
        /// </summary>
        /// <returns></returns>
        public virtual MvcHtmlString ToHtmlString()
        {
            MvcHtmlString mhs = new MvcHtmlString(this.RenderJavascript());
            return mhs;
        }
    }
}
